using Microsoft.VisualStudio.TestTools.UnitTesting;
using PsAccountManager;

namespace PsAccountManagerTest
{
    /// <summary>
    /// Contains all the unit tests for the class Account
    /// </summary>
    [TestClass]
    public class AccountTest
    {

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void CreateAccountValid()
        {
            Account target = new Account("chequing", 0.0);
            Assert.IsNotNull(target,"CreateAccountValid");
        }

        [TestMethod]
        [ExpectedException(typeof(PsAccountManagerException),"ACM-001")]
        public void CreateAccountNull()
        {
            Account target = new Account(null,0.0);
            Assert.Fail("CreateAccountNull: " + target);
        }

        [TestMethod]
        [ExpectedException(typeof(PsAccountManagerException),"ACM-001")]
        public void CreateAccountEmpty()
        {
            Account target = new Account("",0.0);
            Assert.Fail("CreateAccountEmpty: " + target);
        }

        [TestMethod]
        public void TestTransferToValid()
        {
            double startingBalance = 100.0;
            Account fromAccount = new Account("Chequing",startingBalance);
            Account toAccount = new Account("Savings", startingBalance);
            double transferAmount = 50.0;

            Assert.AreEqual(fromAccount.Balance, startingBalance, "TestTransferValid.From.Before");
            Assert.AreEqual(toAccount.Balance, startingBalance, "TestTransferValid.To.Before");
            fromAccount.TransferTo(toAccount, transferAmount);

            Assert.AreEqual(startingBalance - transferAmount, fromAccount.Balance, "TestTransferValid.From.After");
            Assert.AreEqual(startingBalance + transferAmount, toAccount.Balance, "TestTransferToValid.To.After");
        }

        [TestMethod]
        [ExpectedException(typeof(PsAccountManagerException), PsAccountManagerException.NullToAccount)]
        public void TestTransferToNull()
        {
            double startingBalance = 100.0;
            Account fromAccount = new Account("Chequing", startingBalance);
            double transferAmount = 50.0;

            Assert.AreEqual(fromAccount.Balance, startingBalance, "TestTransferValid.From.Before");
            fromAccount.TransferTo(null, transferAmount);

            Assert.Fail("TestTransferToNull.NoExceptionThrown");
        }

        [TestMethod]
        [ExpectedException(typeof(PsAccountManagerException),PsAccountManagerException.TransferAmountExceedsAvailable)]
        public void TestTransferToTooLarge()
        {
            double startingBalance = 100.0;
            Account fromAccount = new Account("Chequing", startingBalance);
            Account toAccount = new Account("Savings", startingBalance);
            double transferAmount = startingBalance + 1;

            Assert.AreEqual(fromAccount.Balance, startingBalance, "TestTransferToTooLarge.From.Before");
            Assert.AreEqual(toAccount.Balance, startingBalance, "TestTransferToTooLarge.To.Before");
            fromAccount.TransferTo(toAccount, transferAmount);

            Assert.Fail("TestTransferToTooLarge.NoExceptionThrown");

        }
    }
}
